/*
textlabel.cpp
(c) 2010 Yury Hamenkov
This file is part of qWordCards.

qWordCards is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

qWordCards is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with qWordCards. If not, see <http://www.gnu.org/licenses/>.
*/

#include "textlabel.h"
#include "preferences.h"

#include <QMouseEvent>

using namespace qWordCards;


TextLabel::TextLabel(QWidget *parent) : QLabel(parent) {
	UpdatePalette ();
}

void TextLabel::UpdateContent(Word &word, bool translation) {
	this->_currentWord = word;
	this->_showTranslation = translation;
	UpdateContent();
}

void TextLabel::UpdateContent() {
	QString t = "<style type=\"text/css\"> div#word { ";
	t += "font-size: " + QString::number(Preferences::wordFont.pointSize()) + "pt; ";
	if (Preferences::wordFont.bold()) {
		t += "font-weight: bold; ";
	}
	if (Preferences::wordFont.italic()) {
		t += "font-style: italic; ";
	}
	if (Preferences::wordFont.underline()) {
		t += "text-decoration: underline; ";
	}
	t += "color: " + Preferences::wordColor.name() + "; } ";


	t += "div#transc { ";
	t += "font-size: " + QString::number(Preferences::transcriptionFont.pointSize()) + "pt; ";
	if (Preferences::transcriptionFont.bold()) {
		t += "font-weight: bold; ";
	}
	if (Preferences::transcriptionFont.italic()) {
		t += "font-style: italic; ";
	}
	if (Preferences::transcriptionFont.underline()) {
		t += "text-decoration: underline; ";
	}
	t += "color: " + Preferences::transcriptionColor.name() + "; } ";


	t += "div#transl { ";
	t += "font-size: " + QString::number(Preferences::translationFont.pointSize()) + "pt; ";
	if (Preferences::translationFont.bold()) {
		t += "font-weight: bold; ";
	}
	if (Preferences::translationFont.italic()) {
		t += "font-style: italic; ";
	}
	if (Preferences::translationFont.underline()) {
		t += "text-decoration: underline; ";
	}
	t += "color: " + Preferences::translationColor.name() + "; } ";


	t += "</style> ";


	t += "<div id=\"word\">" + this->_currentWord.GetWord() + "</div><br>";
	if (this->_currentWord.GetTranscription() != "") {
		t += "<div id=\"transc\">[" + this->_currentWord.GetTranscription() + "]</div><br>";
	}
	if (this->_showTranslation) {
		t += "<div id=\"transl\">" + this->_currentWord.GetTranslation() + "</div>";
	}

	this->setText(t);
}

void TextLabel::UpdatePalette () {
	QPalette palette(this->palette());
	palette.setColor(QPalette::Active, QPalette::Background, Preferences::mainWindowBackColor);
	palette.setColor(QPalette::Inactive, QPalette::Background, Preferences::mainWindowBackColor);
	setPalette(palette);
	UpdateContent();
}

/* virtual */
void TextLabel::mouseMoveEvent (QMouseEvent * event) {
	QLabel::mouseMoveEvent(event);
	event->setAccepted(false);
}

/* virtual */
void TextLabel::mousePressEvent (QMouseEvent * event) {
	QLabel::mousePressEvent(event);
	event->setAccepted(false);
}

/* virtual */
void TextLabel::mouseReleaseEvent (QMouseEvent * event) {
	QLabel::mouseReleaseEvent(event);
	event->setAccepted(false);
}
